package com.box.app.arithmetic

@Suppress("EnumEntryName", "Unused")
internal enum class Operator1 : Operator {
    plus,
    negate,
    inv;

    override val priority = 3

    fun call(a: Number): Number {
        return when (this) {
            plus -> a.plus()
            negate -> a.negate()
            inv -> a.inv()
        }
    }

    override fun toDescribe(isTight: Boolean): String {
        return when (this) {
            plus -> "+"
            negate -> "-"
            inv -> "~"
        }
    }

    override fun toString() = toDescribe(true)

    companion object {
        private fun maybeOf(s: String) = values().singleOrNull { it.toString() == s }

        fun of(s: String) = checkNotNull(maybeOf(s))
    }
}
